package com.rd.student.jike.class4.wanghaixin.test0731;

import java.util.Arrays;

public class Demo {
    public static void main(String[] args) {
        int[] a = method02();
        System.out.println(a.length);
        System.out.println(Arrays.toString(a));
    }

    public static int[] method01(){
        int[] arrays = new int[20];
        int[] arrays1 = new int[50];
        int j = 0;
        for (int i = 0; i < 50; i++) {
            arrays1[i]=-1;
        }
        while(j<20){
            int num =(int)(Math.random()*50);
            if(arrays1[num]==-1){
                arrays[j] = num;
                arrays1[num]=num;
                j++;
            }
        }
        return arrays;
    }

    public static int[] method02(){
        int[] index = new int[20];
        index[0]= (int)(Math.random()*50);
        for (int i = 1; i < 20; i++) {
            int num =(int)Math.random()*50;
            for (int j = 0; j < i; j++) {
                if(index[j]==num){
                    i--;
                    break;
                }
            }
            index[i]=num;
        }
        return index;
    }


}
